package tree.binarytree.recursive;

import java.util.Scanner;

public class BinaryTree {
    private BinTreeNode root;

    public BinaryTree() {
        this.root = null;
    }

    public void createTree() {
        this.setRoot(createSubTree());
    }

    public BinTreeNode createSubTree() {
        BinTreeNode subTree = null;
        String s = new Scanner(System.in).next();

        if (!("#".equals(s))) {
            subTree = new BinTreeNode(s);
            subTree.setLeftChild(createSubTree());
            subTree.setRightChild(createSubTree());
        }
        return subTree;
    }

    public void preOrderTraverse(BinTreeNode root) {
        if (root == null) {
            return;
        }
        System.out.print(root.getData() + " ");
        preOrderTraverse(root.getLeftChild());
        preOrderTraverse(root.getRightChild());
    }

    public BinTreeNode getRoot() {
        return root;
    }

    public void setRoot(BinTreeNode root) {
        this.root = root;
    }
}